package org.wuliu.Controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.wuliu.dao.*;
import org.wuliu.pojo.*;
import org.wuliu.utils.*;

import java.util.List;

@Controller
@RequestMapping("/role")
@CrossOrigin(value = "*")
public class RoleController {
    @Autowired
    private RoleDao roleDao;
    @RequestMapping("/show")
    @ResponseBody
    public ResponseResult getShow(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "5") int limit, Role role){
        Page<Hezhong> pager = PageHelper.startPage(page,limit);
        List<Role> list=roleDao.getList(role);
        return new ResponseResult(pager.getTotal(),list);
    }
    @RequestMapping("/all")
    @ResponseBody
    public ResponseResult getAll(){
        List<Role> list=roleDao.getAll();
        return new ResponseResult(list);
    }
    @RequestMapping("/add")
    @ResponseBody
    public ResponseResult add(Role role){
        roleDao.add(role);
        return ResponseResult.createSuccessResUle();
    }
}
